package com.example.test_example

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.example.test_example.lotteryNine.LotteryView
import kotlin.random.Random


class MainActivity : AppCompatActivity() {

    companion object {
        var iconArray = arrayOf(
            R.mipmap.ac0,
            R.mipmap.ac1,
            R.mipmap.ac2,
            R.mipmap.ac3,
            R.mipmap.ac4,
            R.mipmap.ac5,
            R.mipmap.ac6,
            R.mipmap.ac7
        )
    }

    private var mLotteryView: LotteryView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        mLotteryView = findViewById(R.id.ldv_top)


        //data 传入后台给的抽奖数据
        mLotteryView?.setDataAndListener("", object : LotteryView.LotteryListener {
            override fun onClickLottery() {
                //点击开始抽奖调用抽奖接口后开始抽奖动画
                val result = Random.nextInt(0, 7) //模拟抽奖接口
                mLotteryView?.startLottery(result)
            }

            override fun onEnd() {
                //结束后恢复原样
                Handler(Looper.getMainLooper()).postDelayed({
                    mLotteryView?.resetLottery()
                }, 2000L)
            }
        })

    }




    private fun String.log(){
        Log.e("yufs",this)
    }
}